
/**
*tagfolder
*Licensed under LGPL
*http://code.google.com/p/tagfolder
*chuanshenglu@gmail.com
*xrjieyee@gmail.com
*
*/

#ifndef __TF_NAMED_PIPE_H__
#define __TF_NAMED_PIPE_H__

#include "TFChannel.h"
#include <string>

#if defined( __WINDOWS_PLATFORM__)
#include <windows.h>
#include <TCHAR.h>
#else // #if defined( __WINDOWS_PLATFORM__)
#include <unistd.h>
#endif // #if defined( __WINDOWS_PLATFORM__)


class TFNamedPipe
	:public TFDuplexChannel
{
private:
#if defined( __WINDOWS_PLATFORM__)
	HANDLE	hPipe;
	HANDLE	hFile;
	const TCHAR *DEFAULT_PIPE_NAME;
#else
    const char *DEFAULT_PIPE_NAME;
#endif // #if defined( __WINDOWS_PLATFORM__)
	bool ServerEnd;

public:
	TFNamedPipe();
	TFNamedPipe(TFString&);
	TFNamedPipe(TFNamedPipe&);
	virtual ~TFNamedPipe();
	//
	virtual bool CreatePipe();
	/*
	*Param: Data ptr,size to be Write in byte;
	*Return: if succeeded
	*/
	virtual bool Put(void *, unsigned long);
	virtual bool Put(std::string&);
	/*
	*Param:Data ptr to receive, size to be read in byte;
	*Return: Bytes acctually read;
	*/
	virtual unsigned long Get(void *, unsigned long );

	//Various read function for conveniont;
	virtual char GetChar();
	virtual std::string GetString();
	// protected:
	virtual bool ConnectToPipe();
	virtual bool DisconnectFromPipe();
};

#endif // #ifndef __TF_NAMED_PIPE_H__
